import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Home from '../views/Home.vue'
import Msg from '../views/Msg.vue'
import News from '../views/News.vue'
import MsgDetail from '../views/MsgDetail.vue'
// 声明路由对象, 使用ts,限制类型为数组,泛型为RouteRecordRaw
const routes: Array<RouteRecordRaw> = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [

      {
        
        path: '/home/msg',
        component: Msg,
        children: [{
          path: '/home/msg/detail/:id',
          component: MsgDetail
        }]

      }
    ]
  },
  {
    path: '/about',
    name: 'About',
    // 动态加载 组件,代码分割
    // route level code-splitting  
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),

    children: [{
      path: "/about/news",
      component: News,

    }]
  },

  {
    path: '/',
    redirect: "/home"
  },

]

// 创建路由 ,使用histroy的方式
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
// 导出
export default router




